package com.itheima.reggie.controller;
import com.itheima.reggie.commom.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @author Sea
 * @date 2023/3/9 10:01
 */
@RestController
public class CartController {
    @Autowired
    private CartService cartService;
    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo add(@RequestBody Cart cart){
       Cart cart1= cartService.add(cart);
       return ResultInfo.success(cart1);
    }
    //查询购物车列表
    @GetMapping("/cart/list")
    public ResultInfo list(){
        List<Cart>cartList=cartService.list();
        return ResultInfo.success(cartList);
    }
    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo delete(){
      cartService.deleteList();
        return ResultInfo.success();
    }
    // 修改购物车
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cartParam){// 1.接收参数
        // 2.调用service添加
        Cart cart = cartService.sub(cartParam);
        // 3.返回结果
        return ResultInfo.success(cart);

    }
}
